package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.DamageListGoodsService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.lang.model.element.VariableElement;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: DamageListGoodsController
 * Description:
 * Date: 2022/1/16 18:09
 *
 * @version:
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/damageListGoods")
public class DamageListGoodsController {


    @Autowired
    private DamageListGoodsService damageListGoodsService;



    @PostMapping("/save")
    public ServiceVO saveDamageListGoods(DamageList damageList, String damageListGoodsStr, HttpSession session){





        try {
            damageListGoodsService.saveDamageListGoods(damageList,damageListGoodsStr,session);
            return new ServiceVO<>(100,"请求成功");

        }catch (Exception e){
            e.printStackTrace();
        }

        return new ServiceVO<>(101,"添加或修改失败");


    }



    @PostMapping("/list")
    public Map<String,Object> getDamageListGoods(String  sTime, String  eTime){
        List<DamageList> damageListList = damageListGoodsService.getDamageListGoods(sTime,eTime);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",damageListList);
        return stringObjectHashMap;
    }


    @PostMapping("/goodsList")
    public Map<String,Object> getGoodsList(Integer damageListId){
        List<DamageListGoods> damageListGoodsList = damageListGoodsService.getGoodsList(damageListId);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",damageListGoodsList);
        return stringObjectHashMap;
    }







}
